'use strict';

var config = require('./config');
var nodemailer = require('nodemailer');
var redis = require('./redis');
// Setup Nodemailer transport
var transport = nodemailer.createTransport({
    host: config.server.host,
    port: 12345,
    auth: {
        user: 'admin',
        pass: '123'
    }
});

function getMailOptions(to, subject, html, attachments) {
    var mailOptions = {
        from: '954993153@qq.com', // sender address
        to: '2851561049@qq.com', // list of receivers
        subject: 'nodemailer2.5.0邮件发送', // Subject line
        text: 'Hello world?' // plain text body
        // html: '<h2>nodemailer基本使用:</h2><h3><a href="http://blog.csdn.net/zzwwjjdj1/article/details/51878392">http://blog.csdn.net/zzwwjjdj1/article/details/51878392</a></h3>' // html body
    };
    return mailOptions
}





function SendEmail() {
    transport.sendMail(getMailOptions('', '', '', []), function (error, info) {
        console.log(222222222222222222)
        if (error) {
            return console.log(error);
        }
        console.log('Message sent: %s', info.messageId);
        // Preview only available when sending through an Ethereal account
        console.log('Preview URL: %s', nodemailer.getTestMessageUrl(info));

        // Message sent: <b658f8ca-6296-ccf4-8306-87d57a0b4321@blurdybloop.com>
        // Preview URL: https://ethereal.email/message/WaQKMgKddxQDoou...
    });
    // var queueKey = "queue1";
    // redis.client_4.brpop(queueKey, 10, function (err,data) {
    //     console.log(data[1])
    //     console.log(typeof data[1])
    //     var jsonObject = JSON.parse(data[1]);
    //     var to = jsonObject.to;
    //     var html = jsonObject.html;
    //     var subject = jsonObject.subject;
    //     transport.sendMail(getMailOptions(to, subject, html, []), function (error, info) {
    //         if (error) {
    //             return console.log(error);
    //         }
    //         console.log('Message sent: %s', info.messageId);
    //         // Preview only available when sending through an Ethereal account
    //         console.log('Preview URL: %s', nodemailer.getTestMessageUrl(info));
    //
    //         // Message sent: <b658f8ca-6296-ccf4-8306-87d57a0b4321@blurdybloop.com>
    //         // Preview URL: https://ethereal.email/message/WaQKMgKddxQDoou...
    //     });
    // });

}

SendEmail();